/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * continentsCreator.java
 *
 * Created on 25/04/2011, 09:35:02
 */
package creator;

import utn.tsb.tej.world_logic.CardType;
import utn.tsb.tej.world_logic.Continent;
import csm.uttils.Archive;
import csm.uttils.generics.Roster;

/**
 *
 * @author Administrator
 */
public class continentsCreator extends javax.swing.JFrame {

    /** Creates new form continentsCreator */
    public continentsCreator() {
        initComponents();
        continents = new Roster<Continent>();
     
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        txtContinentName = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtaContinentList = new javax.swing.JTextArea();
        btnAddContinent = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        txtArmiesReward = new javax.swing.JTextField();
        cbxEarth = new javax.swing.JCheckBox();
        cbxWater = new javax.swing.JCheckBox();
        cbxAir = new javax.swing.JCheckBox();
        cbxJoker = new javax.swing.JCheckBox();
        btnSave = new javax.swing.JButton();
        btnLoad = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Nombre");

        jLabel2.setText("Types");

        txtaContinentList.setColumns(20);
        txtaContinentList.setRows(5);
        jScrollPane1.setViewportView(txtaContinentList);

        btnAddContinent.setText("Add Continent");
        btnAddContinent.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddContinentActionPerformed(evt);
            }
        });

        jLabel3.setText("ArmiesReward");

        cbxEarth.setText("EARTH");

        cbxWater.setText("WATER");

        cbxAir.setText("AIR");

        cbxJoker.setText("JOKER");

        btnSave.setText("Save");
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });

        btnLoad.setText("Load");
        btnLoad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLoadActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnSave)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnLoad))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(36, 36, 36)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(48, 48, 48)
                        .addComponent(txtContinentName, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cbxEarth)
                            .addComponent(cbxAir))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cbxJoker)
                            .addComponent(cbxWater)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(txtArmiesReward, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnAddContinent))
                .addContainerGap(16, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(txtContinentName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(cbxEarth)
                                    .addComponent(cbxWater))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(cbxAir)
                                    .addComponent(cbxJoker))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtArmiesReward, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 57, Short.MAX_VALUE)
                        .addComponent(btnAddContinent))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(40, 40, 40)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSave)
                    .addComponent(btnLoad))
                .addGap(32, 32, 32))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAddContinentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddContinentActionPerformed
        String nombre=txtContinentName.getText();
        int armiesReward=Integer.parseInt(txtArmiesReward.getText());
        Continent continent=new Continent();
        continent.setName(nombre);
        continent.setArmiesReward(armiesReward);
        if(cbxEarth.isSelected()){
            continent.addType(CardType.EARTH);
        }
         if(cbxWater.isSelected()){
            continent.addType(CardType.WATER);
        }
         if(cbxAir.isSelected()){
            continent.addType(CardType.AIR);
        }
         if(cbxJoker.isSelected()){
            continent.addType(CardType.JOKER);
        }
        continents.addLast(continent);
        printContinents();
    }//GEN-LAST:event_btnAddContinentActionPerformed

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
        Archive archive=new Archive("tjFiles\\continents.ctj");
        archive.writeRoster(continents);
    }//GEN-LAST:event_btnSaveActionPerformed

    private void btnLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoadActionPerformed
      Archive archive=new Archive("tjFiles\\continents.ctj");
      continents=(Roster<Continent>)archive.readRoster();
      printContinents();
    }//GEN-LAST:event_btnLoadActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new continentsCreator().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddContinent;
    private javax.swing.JButton btnLoad;
    private javax.swing.JButton btnSave;
    private javax.swing.JCheckBox cbxAir;
    private javax.swing.JCheckBox cbxEarth;
    private javax.swing.JCheckBox cbxJoker;
    private javax.swing.JCheckBox cbxWater;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField txtArmiesReward;
    private javax.swing.JTextField txtContinentName;
    private javax.swing.JTextArea txtaContinentList;
    // End of variables declaration//GEN-END:variables
    private Roster<Continent> continents;

    private void printContinents() {
        String text = "";
        for (int i = 0; i < continents.count(); i++) {
            text += continents.getElementInPosition(i).toString() + "\n";
        }
        txtaContinentList.setText(text);
    }
}
